660B - Seating On Bus - CodeForces Solution


implementation *1000

Please click on ads to support us..

Python Code:

nm = [int(el) for el in input().split()]
n,m = nm[0],nm[1]

f1 = [0 for _ in range(n)]
f2 = [0 for _ in range(n)]
f3 = [0 for _ in range(n)]
f4 = [0 for _ in range(n)]

ctd = 1

ix = 0
while ix < n:
    if ctd > m:
        break

    if f1[ix] == 0:
        f1[ix] = ctd
        ctd += 1
    elif f4[ix] == 0:
        f4[ix] = ctd
        ctd += 1
    else:
        ix += 1

ix = 0
while ix < n:
    if ctd > m:
        break

    if f2[ix] == 0:
        f2[ix] = ctd
        ctd += 1
    elif f3[ix] == 0:
        f3[ix] = ctd
        ctd += 1
    else:
        ix += 1

ctd = m
strRes = ""

i = 0
while ctd > 0:
    if i >= n:
        break

    if not f2[i] == 0:
        strRes += f' {f2[i]}'
        f2[i] = 0
        ctd -= 1
    elif not f1[i] == 0:
        strRes += f' {f1[i]}'
        f1[i] = 0
        ctd -= 1
    elif not f3[i] == 0:
        strRes += f' {f3[i]}'
        f3[i] = 0
        ctd -= 1
    elif not f4[i] == 0:
        strRes += f' {f4[i]}'
        f4[i] = 0
        ctd -= 1
    else:
        i += 1

print(strRes.lstrip())
  		  	   						  	 			 	 				

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int a[110][7]; 
void solve(std::istream &in, std::ostream &out){
    int n,m,j=-1,k=0; in>>n>>m; 
    for(int i=0;i<108;i++) for(int q=0;q<6;q++) a[i][q]=0;
    for(int i=1;i<=n;i++){
    	j+=2;
    	if(j>m) break;
    	a[i][1]=j;
	}
	for(int i=1;i<=n;i++){
    	k+=2;
    	if(k>m) break;
    	a[i][4]=k;
	}
	int r=min(j,k),s=max(j,k);
	for(int i=1;i<=n;i++){
    	r+=2;
    	if(r>m) break;
    	a[i][2]=r;
	}
	for(int i=1;i<=n;i++){
    	s+=2;
    	if(s>m) break;
    	a[i][3]=s;
	}
	j=1;
	int order[]={2,1,3,4};
	for(int i=1;i<=n;i++){
		for(int q=0;q<4;q++){
			if(a[i][order[q]]){
				out<<a[i][order[q]]<<" ";
				j++;
				if(j>m) return;
			}
		}
	}
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int tc=1; 
	while(tc--) solve(std::cin, std::cout);
    return 0;
}
/*
	Holy codeforces,
	let me AC!
*/

/*  printf("                                                                          \n");
	printf("                                                                           \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *        *        \n");
	printf("            *           *         *                *                *      \n");
	printf("           *            *         *               *               *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                    *            \n");
	printf("        *               *         *           *                      *            \n");
	printf("      *                  *       *          *                *      *              \n");
	printf("    * * * * * * *          * * *          * * * * * * *        * * *   \n");                      \n");
*/    


Comments

Submit
0 Comments
More Questions

1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares
1659D - Reverse Sort Sum
1659A - Red Versus Blue
1659B - Bit Flipping
1480B - The Great Hero
1519B - The Cake Is a Lie
1659C - Line Empire
515A - Drazil and Date
1084B - Kvass and the Fair Nut
1101A - Minimum Integer
985D - Sand Fortress
1279A - New Year Garland
1279B - Verse For Santa
202A - LLPS
978A - Remove Duplicates
1304A - Two Rabbits
225A - Dice Tower
1660D - Maximum Product Strikes Back
1513A - Array and Peaks
1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading